// 云函数入口文件
const cloud = require('wx-server-sdk');
cloud.init();
 
// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext();
 
  if (event.Content == '1' || event.Content == 'pc') {
    await cloud.openapi.customerServiceMessage.send({
      touser: wxContext.OPENID,
      msgtype: 'link',
      link: {
        title: 'pc端网站',
        description: 'pc版失物招领',
        url: 'http://xxlb.site'
      }
    });
  } else if(event.Content == '2' || event.Content == '客服') {
      await cloud.openapi.customerServiceMessage.send({
        touser: wxContext.OPENID,
        msgtype: 'text',
        text: {
        content: '正在接入人工客服...'
        }
      });
  } else if(event.Content == '3' || event.Content == 'chat') {
    await cloud.openapi.customerServiceMessage.send({
      touser: wxContext.OPENID,
      msgtype: 'text',
      text: {
      content: '正在接入群组聊天...'
      }
    });
  } 
  else {
    await cloud.openapi.customerServiceMessage.send({
      touser: wxContext.OPENID,
      msgtype: 'text',
      text: {
        content: '您好,很高兴为您服务。回复(1或者pc)查看pc版本。回复(2或者客服)接入人工客服。回复(3或者chat)接入群组聊天功能'
      }
    });
  }
 
  return 'success';
};
 